<?php $this->headScript()->appendFile($this->js('plugins/jquery.form.js'))
->appendFile($this->js('plugins/jquery.alerts.js'));
$this->headLink()->appendStylesheet($this->js('css/jquery.alerts.css'))
?>
<style>
.listTable ,#student-table {background:#9ebcdd; width:75%; margin: 5px auto;}
.listTable td {padding:3px;background:#fff;}
.listTable th {padding:3px;font-weight: bold; text-align:center;}
#student-table {text-align:center}
.odd {background:#eef ; }
.even {background:#ffe ;}
.trover{background-color: #eeff88;}
.trclick{background-color: #ffaa00;}
.boy{color:blue}
.girl{color:#f55}
</style>
<script>
$(document).ready(function(){
    // 產生學生名冊
    $(".generate-student-list").click(function(){
        var id = $(this).attr('id').substr(9);
        $.getJSON('<?php echo $this->route("generate-student")?>',{
            sn : id
         },function(data){
             if (data)
                $("#generate-"+id).attr('disabled','disabled');
                $("#delete-"+id).attr('disabled','');
                $("#setup-"+id).attr('disabled','');
        });
    });

    // 刪除學生名冊
    $(".delete-student-list").click(function(){
        if (confirm('<?php echo $this->translate("are you sure delete ?")?>') == false)
            return false;
        var id= $(this).attr('id').substr(7);
        $.getJSON('<?php echo $this->route("delete-student")?>',{
            sn : id
          },
          function(data){
              if (data) {
                  $("#generate-"+id).attr('disabled','');
                  $("#delete-"+id).attr('disabled','disabled');
                  $("#setup-"+id).attr('disabled','disabled');
                  $("#list-students").html('');
              }
         });
    });

    $("#goHomeBtn").click(function(){
        window.location='<?php echo  $this->route("index")?>';
    });

    // 學生設定表列
    $(".setup-student-list").click(function(){
        $(".select-li").removeClass('select-li');
        $(this).parent().addClass('select-li');
        var id = $(this).attr('id').substr(6);
        $.get('<?php echo $this->route("get-class-list")?>',{
            sn : id
        },function(data){
            $("#list-students").html(data);
        });
    });
});
</script>
<style>
#list-semester {height: 120px; overflow: auto; padding:5px}
#list-semester li{padding:3px; border-bottom: thin dotted #ccc;list-style: square;}
.select-li {background:#ff0}
.select-radio{background: #ff0;padding:3px}
.select-type {background: #5df}
.class_select label {cursor: pointer;}
</style>
<form method="post" action="" name="setForm"  id="setForm">
<table class="listTable" >
<tr><th colspan=2 style="background: #fff"><?php echo  $this->translate('rand title')?>--3.學生名冊設定
<input type="button" id="goHomeBtn" value="<?php echo  $this->translate('return home page')?>" />
</th></tr>
<?php if ($this->semesterList):?>
<tr><th colspan=2>點選作業項目</th></tr>
<tr><td colspan=2>
<div id="list-semester">
<ul>
<?php $gradeName = unserialize($this->School['length_name']);?>
<?php foreach($this->semesterList as $val):?>
<li><?php $arr = explode('-',$val['year_semester'])?>
<?php echo sprintf($this->translate('%d year %d semester %s'),$arr[0], $arr[1], $gradeName[$arr[2]])?>
 <input type="button"  id="delete-<?php echo $val['sn']?>" value="刪除名冊檔"  class="delete-student-list"  <?php if ($val['is_over']==Student_Model_StudentSemesterRandGroup::EMPTY_STEP):?>disabled="disabled"<?php endif?>/>
<input type="button"  id="generate-<?php echo $val['sn']?>" value="1.產生名冊檔"  class="generate-student-list"   <?php if ($val['is_over'] > Student_Model_StudentSemesterRandGroup::HAS_STUDENT):?>disabled="disabled"<?php endif?>/>
<input type="button"  id="setup-<?php echo $val['sn']?>" value="2.進行學生設定"  class="setup-student-list"   <?php if ($val['is_over']==Student_Model_StudentSemesterRandGroup::EMPTY_STEP):?>disabled="disabled"<?php endif?>/>
</li>
<?php endforeach;?>
</ul>
</div>
</td></tr>
<?php endif?>
</table>
</form>
<div id="list-students"></div>